Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

walk

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

walk

A node port of python's os.walk

  • 2.3.15
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
688K
increased by8.41%
Maintainers
1
Weekly downloads
 
Created

What is walk?

The 'walk' npm package is used for traversing directories and handling files within those directories. It provides a simple and efficient way to walk through a directory tree, allowing you to perform operations on files and directories as you encounter them.

What are walk's main functionalities?

Walking a directory

This feature allows you to walk through a directory and handle files and directories as they are encountered. The 'file' event is triggered for each file, and the 'directory' event is triggered for each directory.

const walk = require('walk');

const walker = walk.walk('/path/to/directory', {});

walker.on('file', function (root, fileStats, next) {
  console.log('File: ' + fileStats.name);
  next();
});

walker.on('directory', function (root, dirStats, next) {
  console.log('Directory: ' + dirStats.name);
  next();
});

walker.on('end', function () {
  console.log('All files traversed.');
});

Filtering files

This feature allows you to filter out certain directories from being walked. In this example, the 'node_modules' and '.git' directories are excluded from the traversal.

const walk = require('walk');

const walker = walk.walk('/path/to/directory', {
  filters: ['node_modules', '.git']
});

walker.on('file', function (root, fileStats, next) {
  console.log('File: ' + fileStats.name);
  next();
});

walker.on('end', function () {
  console.log('All files traversed.');
});

Handling errors

This feature allows you to handle errors that occur during the directory traversal. The 'errors' event is triggered when an error is encountered, and you can log or handle the error as needed.

const walk = require('walk');

const walker = walk.walk('/path/to/directory', {});

walker.on('file', function (root, fileStats, next) {
  console.log('File: ' + fileStats.name);
  next();
});

walker.on('errors', function (root, nodeStatsArray, next) {
  nodeStatsArray.forEach(function (n) {
    console.error('Error: ' + n.error.message);
  });
  next();
});

walker.on('end', function () {
  console.log('All files traversed.');
});

Other packages similar to walk

Keywords

FAQs

Package last updated on 22 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc